var token = "no";

function getUserInfo() {
    $.ajax({
        url: "/apis/user/loginByToken",
        type: "POST",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        headers: {
            token: token //这里是Token
        },
        cache: false,//设置不缓存
        success: getUserSuccess,
        error: showErrorInfo
    });
    return false;
}

function getUserSuccess(data){
    if(!data.flag) {
        window.location.href = "../index.html";
        alert("请先登录！");
    } else {
        var user = JSON.parse(data.msg);
        userName = user['name'];
        role = user['role'];
        if (role.indexOf("教师") == 0){
        }
        else{
            //权限不够
            alert("没有权限！");
            window.location.href = "../index.html";
        }
    }
}

$(document).ready(function () {
        token = getCookie("token");
        getUserInfo();
    }
);



